package com.foreknow.demo16;

import java.io.*;

public class Employee implements Serializable {
    private String name;
    private int age;
    private String dept;

    public Employee(String name, int age, String dept) {
        this.name = name;
        this.age = age;
        this.dept = dept;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }


    public void setAge(int age) {
        this.age = age;
    }

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public void showInfo() {
        System.out.println("name: " + getName() + "age: " + getAge() +"dept: " + getDept());
    }

    public static void main(String[] args) {

        try {
//                    FileOutputStream fis = new FileOutputStream("xxx.ser"); //节点流
//                    ObjectOutputStream oos = new ObjectOutputStream(fis); //处理流用于向文件中写对象
//                    oos.writeObject(new Employee("fender",20,"pro"));
//                    oos.writeObject(new Employee("gibson",30,"market"));
//                    oos.close();
            //反序列化
            FileInputStream fis = new FileInputStream("xxx.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Employee employee = (Employee) ois.readObject();
            employee.showInfo();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
